﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL;
using Utils.ControlToLoad;
using Utils.Exceptions;

namespace Prototype1.MetaEditControls
{
    public partial class ControlTemplateDislocations : System.Web.UI.UserControl, IControlToLoadW
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region IControlToLoadW Members

        public Guid Id
        {
            get
            {
                if (ViewState["Id"] != null)
                    return (Guid)ViewState["Id"];
                else
                    throw new ValueNotAvailableException();
            }
            set { ViewState["Id"] = value; }
        }

        public void Save()
        {
            ExpenseTypeDislocation exp = new ExpenseTypeDislocation();
            exp.Id = this.Id;
            exp.RequiresArrival = this.cb_RequiresArr.Checked;
            exp.RequiresDeparture = this.cb_RequiresDepart.Checked;

            using (DataAccessDataContext dc = new DataAccessDataContext())
            {
                dc.ExpenseTypeDislocations.InsertOnSubmit(exp);
                dc.SubmitChanges();
            }
        }

        public void Bind(Guid Id)
        {
            this.Id = Id;
        }

        #endregion
    }
}